﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyHocPhi.Model;
using System.Data.Entity;
namespace QuanLyHocPhi.BLL
{
    class BizLopGoc
    {
        internal static Lop GetLopByMaLop(string maLop)
        {
            using (var context = new QLHPEntities())
            {
                return context.LopDbSet.FirstOrDefault(e => e.MaLop == maLop);
            }
        }

        internal static Lop GetLopIncludeTruongByMaLop(string maLop)
        {
            using (var context = new QLHPEntities())
            {
                return context.LopDbSet.Include(e => e.Truong).FirstOrDefault(e => e.MaLop == maLop);
            }
        }

        internal static IList<SinhVien> GetListSinhVien(string maLop)
        {
            using (var context = new QLHPEntities())
            {
                var query = from sinhVien in context.SinhVienDbSet.Include("LopHocPhan_SinhVienCollection")
                            where sinhVien.KC_MaLop == maLop //&& sinhVien.MaLoai == SinhVien.MaLoai_KhongChuyen
                            orderby sinhVien.Ten, sinhVien.HoDem
                            select sinhVien;
                return query.ToList().ToSortableBindingList();
            }
        }
        internal static IList<SinhVien> GetListSinhVienChuyen(string maLop)
        {
            using (var context = new QLHPEntities())
            {
                var query = from sinhVien in context.SinhVienDbSet.Include("LopHocPhan_SinhVienCollection")
                            where sinhVien.KC_MaLop == maLop && sinhVien.MaLoai == SinhVien.MaLoai_Chuyen
                            orderby sinhVien.Ten, sinhVien.HoDem
                            select sinhVien;
                return query.ToList().ToSortableBindingList();
            }
        }
        /// <summary>
        /// Lấy danh sách các khóa tuyển sinh của một trường
        /// </summary>
        /// <returns></returns>
        internal static IList<string> GetList_KhoaTuyenSinh(string maTruong)
        {
            using (var context = new QLHPEntities())
            {
                var lstGroupNamTuyenSinh = from lop in context.LopDbSet
                                           where lop.MaTruong ==maTruong
                                     group lop by lop.NamTuyenSinh into LopGroup
                                     orderby LopGroup.Key descending
                                     select new { NamTuyenSinh = LopGroup.Key };
                var lstNamTuyenSinh = new List<string>();
                foreach (var group in lstGroupNamTuyenSinh)
                    lstNamTuyenSinh.Add(group.NamTuyenSinh.ToString());
                return lstNamTuyenSinh;
            }
        }
    }
}
